package com.demo.base;

import com.baomidou.mybatisplus.core.conditions.query.*;
import com.demo.base.*;
import org.springframework.stereotype.Component;

/**
 * AIKA
 * 2023/5/18
 */


@Component
public class BaseWrapper<T extends BaseModel> {


    public QueryWrapper base(Class<T> clazz, BaseDto dto) {
        QueryWrapper<T> wrapper = new QueryWrapper<>();
        wrapper.eq(dto.getId() != null, "id", dto.getId());
        wrapper.like(dto.getName() != null, "name", dto.getName());
        wrapper.orderByDesc(false,"update_time");
        return wrapper;
    }

    public QueryWrapper<T> wrapper(Class<T> clazz, BaseDto dto) {
        QueryWrapper<T> wrapper = base(clazz, dto);
        return wrapper;
    }


    @Deprecated
    public static <T> LambdaQueryWrapper<T> lambda(Class<T> clazz, BaseDto dto) {
        LambdaQueryWrapper<T> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(dto.getId() != null, s -> dto.getId(), dto.getId());
        wrapper.like(dto.getName() != null, s -> dto.getName(), dto.getName());
        return wrapper;
    }


}
